package com.phenix.mvp.base.mvp;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.phenix.mvp.util.TUtil;

import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * @author  zhouphenix on 2017-2-22.
 */
public abstract class BaseFragment<P extends BaseMVPresenter> extends Fragment {
    public P mPresenter;
    Unbinder unbinder;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(getLayoutId(), container, false);
        unbinder = ButterKnife.bind(this, view);
        mPresenter = TUtil.getInstance(this, 0);
        if (this instanceof BaseView) mPresenter.setView(this);
        return view;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (null != mPresenter) mPresenter.onDetach();
        unbinder.unbind();
    }

    public abstract int getLayoutId() ;
}
